package com.lz.football.module.leagueMatch.item
{
	import com.common.utils.DisplayObjectUtil;
	import com.liangzhong.events.LeagueMatchEvent;
	import com.liangzhong.model.club.vo.NpcClubInfoVo;
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import lz.controls.ImageContain;
	import lz.controls.LItem;
	import lz.controls.events.ListEvent;

	/**
	 *队伍item 
	 * @author lake
	 * 
	 */	
	public class TeamItem extends LItem implements IComponent
	{
		/**
		 *球队级别 
		 */		
		private var starLv 		:MovieClip;
		/**
		 *球队名称 
		 */		
		private var txtName 		:TextField;
		/**
		 *比分 
		 */		
		public var txtScore 		:TextField;
		/**
		 *选中状态 
		 */		
		private var selectMc		:MovieClip;
		/**
		 *移上状态 
		 */		
		private var overtMc		:MovieClip;
		/**
		 *挑战按钮 
		 */		
		public var challengeBtn		:SimpleButton;
		/**
		 *是否已经赢了 
		 */		
		public var isWin			:Boolean;
		/**
		 * 是否可以比赛
		 */		
		public var isCan			:Boolean ;
		/**
		 *数组索引 
		 */		
		public var index			:int;
		/**
		 *队徽类型 
		 */		
		private var iconType 		:int;
		/**
		 *队徽容器 
		 */		
		private var _image 		:ImageContain;
		
		public function TeamItem()
		{
			super();
		}
		/**
		 *设置获取数据 
		 * @param value
		 * 
		 */		
		override public function set data(value:*):void
		{
			if(value == null)
			{
				_symbolSkin.visible = false;
				return;
			}
			_symbolSkin.visible = true;
			super.data = value;
			setPubInfo();
		}
		override public function get data():*
		{
			return super.data;
		}
		/**
		 *设置公用信息 
		 * 
		 */		
		private function setPubInfo():void
		{
			if(_data == null)
			{
				return;
			}
			var npcClubVo :NpcClubInfoVo = _data;
			_symbolSkin.mc.starLv.gotoAndStop(int(npcClubVo.level/10));
			_symbolSkin.mc.txtName.text = npcClubVo.name;
			if(_symbolSkin.selectMc)
			{
				_symbolSkin.selectMc.visible = false;
			}
			setIconData();
		}
		/**
		 *设置队徽类型 
		 * @param type
		 * 
		 */		
		public function setIconType(type :int):void
		{
			iconType = type;
			setIconData();
		}
		/**
		 *设置队徽数据 
		 */		
		private function setIconData():void
		{
			var npcClubVo :NpcClubInfoVo = _data;
			if(npcClubVo == null)
			{
				return;
			}
			switch(iconType)
			{
				case 1://30
				{
					if(npcClubVo.imgObj == null)
					{
						npcClubVo.imgObj = new ImageContain();
						npcClubVo.imgObj.setSize(30,30);
						npcClubVo.imgObj.url = npcClubVo.url_30;
					}
					break;
				}
			}
			if(npcClubVo.imgObj)
			{
				DisplayObjectUtil.removeAllChildren(_symbolSkin.mc.iconContainer);
				_symbolSkin.mc.iconContainer.addChild(npcClubVo.imgObj);
			}
		}
		/**
		 *设置比分 
		 * @param hg
		 * @param gg
		 */		
		public function setScore(hgoal:int,ggoal:int):void
		{
			_symbolSkin.gotoAndStop(3);
			_symbolSkin.mc.txtScore.text = hgoal + ":" + ggoal;
			setPubInfo();
		}
		/**
		 *设置当前队伍状态 
		 */		
		public function setCurTeam():void
		{
			_symbolSkin.gotoAndStop(2);
			setPubInfo();
		}
		/**
		 *设置未挑战状态 
		 * 
		 */		
		public function setNoneTeam():void
		{
			_symbolSkin.gotoAndStop(1);
			setPubInfo();
		}
		/**
		 * 选择
		 * 
		 */		
		override public function select():void
		{
			if(_symbolSkin.selectMc)
			{
				_symbolSkin.selectMc.visible = true;
			}
		}
		/**
		 * 
		 * 去除选择
		 */		
		override public function unSelect():void
		{
			if(_symbolSkin.selectMc)
			{
				_symbolSkin.selectMc.visible = false;
			}
		}
		/**
		 *初始化 
		 * 
		 */		
		public function initUI(view:Object=null):void
		{
			_symbolSkin = view as MovieClip;
			//starLv = _symbolSkin.starLv;
			//txtName = _symbolSkin.txtName;
			//txtScore = _symbolSkin.txtScore;
			//selectMc = _symbolSkin.selectMc;
			//overtMc = _symbolSkin.overtMc;
			//challengeBtn = _symbolSkin.challengeBtn;
			//txtScore.text = "";
			//txtScore.visible = true;
			//selectMc.visible = false;
			//overtMc.visible = false;
			//challengeBtn.visible = false;
			if(_symbolSkin.selectMc)
			{
				_symbolSkin.selectMc.visible = false;
			}
			addEvtListener();
		}
		/**
		 *注册事件 
		 * 
		 */	
		public function addEvtListener():void
		{
			_symbolSkin.addEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			_symbolSkin.addEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			_symbolSkin.addEventListener(MouseEvent.CLICK,onClickHandler);
			//challengeBtn.addEventListener(MouseEvent.CLICK,challengeHandler);
		}
		/**
		 * 移上
		 * @param e
		 * 
		 */		
		protected function onOverHandler(e :MouseEvent):void
		{
			//overtMc.visible = true;
		}
		/**
		 * 移出
		 * @param e
		 * 
		 */		
		protected function onOutHandler(e :MouseEvent):void
		{
			//overtMc.visible = false;
		}
		/**
		 * 单击
		 * @param e
		 * 
		 */		
		protected function onClickHandler(e:MouseEvent):void
		{
			this.dispatchEvent(new ListEvent(ListEvent.ITEM_CLICK,true,false,-1,-1,-1,_data));
		}
		/**
		 *挑战 
		 * @param e
		 * 
		 */		
		protected function challengeHandler(e :MouseEvent):void
		{
			var param :Object = {};
			param.cid = data.cid;
			_symbolSkin.dispatchEvent(new LeagueMatchEvent(LeagueMatchEvent.BASE_MATCH_START,param,true));
			challengeBtn.visible = false;
		}
		/**
		 *删除事件 
		 * 
		 */	
		public function removeEvtListener():void
		{
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OVER,onOverHandler);
			_symbolSkin.removeEventListener(MouseEvent.ROLL_OUT,onOutHandler);
			_symbolSkin.removeEventListener(MouseEvent.CLICK,onClickHandler);
			//challengeBtn.removeEventListener(MouseEvent.CLICK,challengeHandler);
		}
		/**
		 *销毁 
		 * 
		 */	
		public function destroyView():void
		{
			removeEvtListener();
			if(_image)
			{
				_image.clear();
				_image = null;
			}
			var npcClubVo :NpcClubInfoVo = _data;
			if(npcClubVo)
			{
				npcClubVo.imgObj = null;
			}
			_data = null;
		}
	}
}